import datetime

from pydantic import BaseModel, Field
from typing import Optional, List


class OrderModel(BaseModel):
    id: Optional[int] = Field(None, title="id")
    state: Optional[int] = Field(None,
                                 title="状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    create_time: Optional[datetime.datetime] = Field(None, title="创建时间")
    order_id: Optional[str] = Field(None, title="单号")
    user_id: Optional[str] = Field(None, title="申请人id")
    phone: Optional[str] = Field(None, title="手机号")
    department_id: Optional[str] = Field(None, title="用车部门")
    use_user_id: Optional[str] = Field(None, title="用车人id")
    rading_count: Optional[int] = Field(None, title="乘坐人数")
    car_count: Optional[int] = Field(None, title="用车数量")
    expected_mileage: Optional[float] = Field(None, title="预计里程")
    start: Optional[str] = Field(None, title="出发地")
    plan_begin_time: Optional[datetime.datetime] = Field(None, title="预计出车时间")
    plan_end_time: Optional[datetime.datetime] = Field(None, title="预计回车时间")
    use_car_type: Optional[str] = Field(None, title="用车类型（个人用车，领导用车，客户用车）")
    car_model: Optional[str] = Field(None, title="车型")
    car_type: Optional[str] = Field(None, title="车辆类型")
    dispatch_type: Optional[str] = Field(None, title="调度类型（普通调度，应急调度）")
    remark: Optional[str] = Field(None, title="用车备注")
    create_by: Optional[str] = Field(None, title="创建人")
    update_time: Optional[datetime.datetime] = Field(None, title="修改时间")
    update_by: Optional[str] = Field(None, title="修改人")
    start_time: Optional[datetime.datetime] = Field(None, title="开始时间")
    end_time: Optional[datetime.datetime] = Field(None, title="结束时间")
    destination_list: Optional[List] = Field(None, title="目的地（可以有多个）用||分割")
    # name
    use_car_type_name: Optional[str] = Field(None, title="用车类型-中文")
    car_model_name: Optional[str] = Field(None, title="车型-中文")
    car_type_name: Optional[str] = Field(None, title="车辆类型-中文")


class OrderModelForDriverPage(BaseModel):
    id: Optional[int] = Field(None, title="id")
    state: Optional[int] = Field(None,
                                 title="状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    create_time: Optional[datetime.datetime] = Field(None, title="创建时间")
    order_id: Optional[str] = Field(None, title="单号")
    user_id: Optional[str] = Field(None, title="申请人id")
    phone: Optional[str] = Field(None, title="手机号")
    department_id: Optional[str] = Field(None, title="用车部门")
    use_user_id: Optional[str] = Field(None, title="用车人id")
    rading_count: Optional[int] = Field(None, title="乘坐人数")
    car_count: Optional[int] = Field(None, title="用车数量")
    expected_mileage: Optional[float] = Field(None, title="预计里程")
    start: Optional[str] = Field(None, title="出发地")
    plan_begin_time: Optional[datetime.datetime] = Field(None, title="预计出车时间")
    plan_end_time: Optional[datetime.datetime] = Field(None, title="预计回车时间")
    use_car_type: Optional[str] = Field(None, title="用车类型（个人用车，领导用车，客户用车）")
    car_model: Optional[str] = Field(None, title="车型")
    car_type: Optional[str] = Field(None, title="车辆类型")
    dispatch_type: Optional[str] = Field(None, title="调度类型（普通调度，应急调度）")
    remark: Optional[str] = Field(None, title="用车备注")
    create_by: Optional[str] = Field(None, title="创建人")
    update_time: Optional[datetime.datetime] = Field(None, title="修改时间")
    update_by: Optional[str] = Field(None, title="修改人")
    start_time: Optional[datetime.datetime] = Field(None, title="开始时间")
    end_time: Optional[datetime.datetime] = Field(None, title="结束时间")
    destination_list: Optional[List] = Field(None, title="目的地（可以有多个）用||分割")
    # name
    use_car_type_name: Optional[str] = Field(None, title="用车类型-中文")
    car_model_name: Optional[str] = Field(None, title="车型-中文")
    car_type_name: Optional[str] = Field(None, title="车辆类型-中文")
    bill_type: Optional[str] = Field(None, title="结算类型")

class OrderModelForDispatchUrgent(OrderModel):
    id: Optional[int] = Field(None, title="id")
    state: Optional[int] = Field(None,
                                 title="状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    create_time: Optional[datetime.datetime] = Field(None, title="创建时间")
    order_id: Optional[str] = Field(None, title="单号")
    user_id: Optional[str] = Field(None, title="申请人id")
    phone: Optional[str] = Field(None, title="手机号")
    department_id: Optional[str] = Field(None, title="用车部门")
    use_user_id: Optional[str] = Field(None, title="用车人id")
    rading_count: Optional[int] = Field(None, title="乘坐人数")
    car_count: Optional[int] = Field(None, title="用车数量")
    expected_mileage: Optional[float] = Field(None, title="预计里程")
    start: Optional[str] = Field(None, title="出发地")
    destination_list: Optional[List] = Field(None, title="目的地（可以有多个）用||分割")
    plan_begin_time: Optional[datetime.datetime] = Field(None, title="预计出车时间")
    plan_end_time: Optional[datetime.datetime] = Field(None, title="预计回车时间")
    use_car_type: Optional[str] = Field(None, title="用车类型（个人用车，领导用车，客户用车）")
    dispatch_type: Optional[str] = Field(None, title="调度类型（普通调度，应急调度）")
    remark: Optional[str] = Field(None, title="用车备注")
    create_by: Optional[str] = Field(None, title="创建人")
    update_time: Optional[datetime.datetime] = Field(None, title="修改时间")
    update_by: Optional[str] = Field(None, title="修改人")
    start_time: Optional[datetime.datetime] = Field(None, title="开始时间")
    end_time: Optional[datetime.datetime] = Field(None, title="结束时间")
    #
    driver_id: Optional[str] = Field(None, title="驾驶员id")
    driver_phone: Optional[str] = Field(None, title="驾驶员电话")
    car_id: Optional[str] = Field(None, title="车辆id")
    car_model: Optional[str] = Field(None, title="车型")
    car_type: Optional[str] = Field(None, title="车辆类型")


class OrderModelForQuery(BaseModel):
    order_id: Optional[str] = Field(None, title="单号")
    user_id: Optional[str] = Field(None, title="申请人id")
    department_id: Optional[str] = Field(None, title="用车部门")
    state: Optional[int] = Field(None,
                                 title="状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    stateList: Optional[List] = Field(None,
                                 title="状态集合（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    start_time: Optional[datetime.datetime] = Field(None, title="开始时间")
    end_time: Optional[datetime.datetime] = Field(None, title="结束时间")
    card_state: Optional[str] = Field(None, title="用车审批,车辆调度,任务进行中")
    bill_state: Optional[str] = Field(None, title="未结算 已结算")
    driver_id: Optional[str] = Field(None, title="司机id")


class OrderModelForPage(BaseModel):
    id: Optional[int] = Field(None, title="主键")
    order_id: Optional[str] = Field(None, title="单号")
    department_name: Optional[str] = Field(None, title="用车部门名称")
    dispatch_type: Optional[str] = Field(None, title="调度类型")
    use_car_type: Optional[str] = Field(None, title="用车类型")
    user_name: Optional[str] = Field(None, title="用车人")
    driver_name: Optional[str] = Field(None, title="驾驶员")
    plan_begin_time: Optional[datetime.datetime] = Field(None, title="预计出车时间")
    plan_end_time: Optional[datetime.datetime] = Field(None, title="预计回车时间")
    reality_begin_time: Optional[datetime.datetime] = Field(None, comment='实际出车时间')
    reality_end_time: Optional[datetime.datetime] = Field(None, comment='实际回车时间')
    sheet_mileage: Optional[Optional[float]] = Field(None, comment='仪表里程')
    time: Optional[int] = Field(None, comment='时长')
    state: Optional[int] = Field(None,
                                 title="状态（1 待审核，2 待调度，3 审核驳回，4  待确认，5 待开始，6 进行中，7 已完结，8 已取消）")
    expenses: Optional[Optional[float]] = Field(None, comment='金额')
    destination: Optional[List[str]] = Field(None, comment='目的地')
    #
    use_car_type_name: Optional[str] = Field(None, title="用车类型-名称")
    bill_type: Optional[str] = Field(None, title="用车类型-名称")
    createby: Optional[str] = Field(None, title="申请人")



class OrderPageObject(OrderModelForQuery):
    """
    岗位管理分页查询模型
    """
    page_num: int
    page_size: int


class CrudOrderResponse(BaseModel):
    is_success: bool
    message: str

class OrderPlanTime(BaseModel):
    plan_begin_time: Optional[datetime.datetime] = Field(None, title="预计出车时间")
    plan_end_time: Optional[datetime.datetime] = Field(None, title="预计回车时间")

class OrderModelForExpectedMileage(BaseModel):

    start: Optional[str] = Field(None, title="出发地")
    destination_list: Optional[List] = Field(None, title="目的地（可以有多个")

